<?php

namespace app\admin\model\room;

use app\admin\model\users\Users;
use think\Model;


class Room extends Model
{

    

    

    // 表名
    protected $name = 'room';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'type_text',
        'sex_text',
        'hire_type_text',
        'amount_type_text',
        'renovation_type_text',
        'room_type_text',
        'lift_text',
        'tags_text',
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
    }

    public function getSexList()
    {
        return ['0' => __('Sex 0'), '1' => __('Sex 1')];
    }

    public function getHireTypeList()
    {
        return ['0' => __('Hire_type 0'), '1' => __('Hire_type 1')];
    }

    public function getAmountTypeList()
    {
        return ['0' => __('Amount_type 0'), '1' => __('Amount_type 1'), '2' => __('Amount_type 2'), '3' => __('Amount_type 3')];
    }

    public function getRenovationTypeList()
    {
        return ['0' => __('Renovation_type 0'), '1' => __('Renovation_type 1'), '2' => __('Renovation_type 2'), '3' => __('Renovation_type 3')];
    }

    public function getRoomTypeList()
    {
        return ['0' => __('Room_type 0'), '1' => __('Room_type 1'), '2' => __('Room_type 2'), '3' => __('Room_type 3')];
    }

    public function getLiftList()
    {
        return ['0' => __('Lift 0'), '1' => __('Lift 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getHireTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['hire_type']) ? $data['hire_type'] : '');
        $list = $this->getHireTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAmountTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['amount_type']) ? $data['amount_type'] : '');
        $list = $this->getAmountTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRenovationTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['renovation_type']) ? $data['renovation_type'] : '');
        $list = $this->getRenovationTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRoomTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['room_type']) ? $data['room_type'] : '');
        $list = $this->getRoomTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLiftTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['lift']) ? $data['lift'] : '');
        $list = $this->getLiftList();
        return isset($list[$value]) ? $list[$value] : '';
    }
	
	
	function users()
	{
		return $this->belongsTo(Users::class,'users_id');
	}
	
	public function getTagsTextAttr($value, $data){
		$value = $value ?? (isset($data['tags']) ? $data['tags'] : '');
		$valueArr = explode(',', $value);
		return implode(',',array_column(RoomTags::all($valueArr),'name'));
	}




}
